﻿using delitel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Xml.Linq;

namespace delitel.ViewModel
{
    internal class ResistorsViewModel: MainViewModel
    {
        public ResistorsViewModel()
        {
          
            FirstVariantExecution = new LambdaCommand(OnFirstVariantExecutionExecuted, canFirstVariantExecutionExecute);
       PogreshComand=new LambdaCommand(OnPogreshComandExecuted, canPogreshComandExecute);
            CommandParametrs = new LambdaCommand(OnCommandParametrsExecuted, canCommandParametrsExecute);
            ComForVariantExecution= new LambdaCommand(OnComForVariantExecutionExecuted, canComForVariantExecutionExecute);
            ComTwoVariantExecution= new LambdaCommand(OnComTwoVariantExecutionExecuted, canComTwoVariantExecutionExecute);
            ComThereVariantExecution=new LambdaCommand(OnComThereVariantExecutionExecuted, canComThereVariantExecutionExecute);
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            #region формирование и передача данных
            var PristavTok = new List<Pristavka>();
            var PristavVolta = new List<Pristavka>();

            var PristavRessiters = new List<Pristavka>();
            var PristavCapascity = new List<Pristavka>();
            var PristavInduction = new List<Pristavka>();

            var PristavActivePower = new List<Pristavka>();
            var PristavReacPower = new List<Pristavka>();
            var PristavFullPower = new List<Pristavka>();

            var PristavChactota = new List<Pristavka>();
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavTok.Add(new Pristavka(){ Name = "МА" });
            PristavTok.Add(new Pristavka() { Name = "кА" });
            PristavTok.Add(new Pristavka() { Name = "А" });
            PristavTok.Add(new Pristavka() { Name = "мА" });
            PristavTok.Add(new Pristavka() { Name = "мкА" });

            Tok = PristavTok;
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavVolta.Add(new Pristavka() { Name = "МВ" });
            PristavVolta.Add(new Pristavka() { Name = "кВ" });
            PristavVolta.Add(new Pristavka() { Name = "В" });
            PristavVolta.Add(new Pristavka() { Name = "мВ" });
            PristavVolta.Add(new Pristavka() { Name = "мкВ" });

            Volta = PristavVolta;
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavRessiters.Add(new Pristavka() { Name = "ТОм" }); 
            PristavRessiters.Add(new Pristavka() { Name = "ГОм" });
            PristavRessiters.Add(new Pristavka() { Name = "МОм" });
            PristavRessiters.Add(new Pristavka() { Name = "кОм" });
            PristavRessiters.Add(new Pristavka() { Name = "Ом" });
            PristavRessiters.Add(new Pristavka() { Name = "мОм" });
            PristavRessiters.Add(new Pristavka() { Name = "мкОм" });

            Resisters = PristavRessiters;

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavCapascity.Add(new Pristavka() { Name = "Ф" });
            PristavCapascity.Add(new Pristavka() { Name = "мФ" });
            PristavCapascity.Add(new Pristavka() { Name = "мкФ" });
            PristavCapascity.Add(new Pristavka() { Name = "нФ" });
            PristavCapascity.Add(new Pristavka() { Name = "пФ" });

            Capacity = PristavCapascity;
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavInduction.Add(new Pristavka() { Name = "Гн" });
            PristavInduction.Add(new Pristavka() { Name = "мГн" });
            PristavInduction.Add(new Pristavka() { Name = "мкГн" });
            PristavInduction.Add(new Pristavka() { Name = "нГн" });
     

            Induction = PristavInduction;
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavActivePower.Add(new Pristavka() { Name = "ГВт" });
            PristavActivePower.Add(new Pristavka() { Name = "МВт" });
            PristavActivePower.Add(new Pristavka() { Name = "кВт" });
            PristavActivePower.Add(new Pristavka() { Name = "Вт" });
            PristavActivePower.Add(new Pristavka() { Name = "мВт" });
            PristavActivePower.Add(new Pristavka() { Name = "мкВт" });

            ActivePower = PristavActivePower;         
           /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavReacPower.Add(new Pristavka() { Name = "ГВАр" });
            PristavReacPower.Add(new Pristavka() { Name = "МВАр" });
            PristavReacPower.Add(new Pristavka() { Name = "кВАр" });
            PristavReacPower.Add(new Pristavka() { Name = "ВАр" });
            PristavReacPower.Add(new Pristavka() { Name = "мВАр" });
            PristavReacPower.Add(new Pristavka() { Name = "мкВАр" });
            PristavReacPower.Add(new Pristavka() { Name = "нВАр" });

            ReactPower = PristavReacPower;
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavFullPower.Add(new Pristavka() { Name = "ГВА" });
            PristavFullPower.Add(new Pristavka() { Name = "МВА" });
            PristavFullPower.Add(new Pristavka() { Name = "кВА" });
            PristavFullPower.Add(new Pristavka() { Name = "ВА" });
            PristavFullPower.Add(new Pristavka() { Name = "мВА" });
            PristavFullPower.Add(new Pristavka() { Name = "мкВА" });
            PristavFullPower.Add(new Pristavka() { Name = "нВА" });

            FullPowers = PristavFullPower;
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/


            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
            PristavChactota.Add(new Pristavka() { Name = "ГГц" });
            PristavChactota.Add(new Pristavka() { Name = "МГц" });
            PristavChactota.Add(new Pristavka() { Name = "кГц" });
            PristavChactota.Add(new Pristavka() { Name = "Гц" });
            PristavChactota.Add(new Pristavka() { Name = "мГц" });
            PristavChactota.Add(new Pristavka() { Name = "мкГц" });

            Chactots = PristavChactota;
            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

            #endregion

            /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
        }
        #region создание данных
        private IEnumerable<Pristavka> ptok;
        public IEnumerable<Pristavka> Tok { get => ptok; set => Set(ref ptok, value); }

        private IEnumerable<Pristavka> pvolta;
        public IEnumerable<Pristavka> Volta { get => pvolta; set => Set(ref pvolta, value); }

        private IEnumerable<Pristavka> presisters;
        public IEnumerable<Pristavka> Resisters { get => presisters; set => Set(ref presisters, value); }

        private IEnumerable<Pristavka> pcapacity;
        public IEnumerable<Pristavka> Capacity { get => pcapacity; set => Set(ref pcapacity, value); }

        private IEnumerable<Pristavka> pinduction;
        public IEnumerable<Pristavka> Induction { get => pinduction; set => Set(ref pinduction, value); }

        private IEnumerable<Pristavka> pactivePower;
        public IEnumerable<Pristavka> ActivePower { get => pactivePower; set => Set(ref pactivePower, value); }

        private IEnumerable<Pristavka> preacPower;
        public IEnumerable<Pristavka> ReactPower { get => preacPower; set => Set(ref preacPower, value); }

        private IEnumerable<Pristavka> pfullPowers;
        public IEnumerable<Pristavka> FullPowers { get =>pfullPowers; set => Set(ref pfullPowers, value); }

        private IEnumerable<Pristavka> pchactots;
        public IEnumerable<Pristavka> Chactots { get => pchactots; set => Set(ref pchactots, value); }
        #endregion

        /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
      private   bool FlagOneScript=false;
    

        #region входные данные
        private double voltage = 0;
        public double Voltage { get => voltage; set => Set(ref voltage, value); }

        private double phase = 0;
        public double Phase { get => phase; set => Set(ref phase, value); }

        private bool phasePositiv = true;
        public bool PhasePositiv { get => phasePositiv; set => Set(ref phasePositiv, value); }

        private bool phaseNegativ;
        public bool PhaseNegativ { get => phaseNegativ; set => Set(ref phaseNegativ, value); }


        private double chactota = 0;
        public double Chactota { get => chactota; set => Set(ref chactota, value); }

        private double loadResit = 0;
        public double LoadResit { get => loadResit; set => Set(ref loadResit, value); }

        private double loadCapac = 0;
        public double LoadCapac { get => loadCapac; set => Set(ref loadCapac, value); }

        private double loadInduc = 0;
        public double LoadInduc { get => loadInduc; set => Set(ref loadInduc, value); }

        /*-------------------------------------------------------------------------------------------------------------------------*/


        #region  условия сигнала и нагрузки
        private bool flagChangedConstMode = true;
        private bool flagChangedPMode = false;
        private bool flagPower = false;
        private bool flagPowerRessit= true;
        private bool flagPowerCapacity = false;
        private bool flagPowerInduction = false;

        public bool FlagChangedConstMode { get => flagChangedConstMode; set => Set(ref flagChangedConstMode, value); }
        public bool FlagChangedPMode { get =>flagChangedPMode; set => Set(ref flagChangedPMode, value); }
        public bool FlagPower { get => flagPower; set => Set(ref flagPower, value); }
             public bool FlagPowerRessit { get => flagPowerRessit; set=>Set(ref flagPowerRessit, value); }
             public bool FlagPowerCapacity { get => flagPowerCapacity; set => Set(ref flagPowerCapacity, value); }
             public bool FlagPowerInduction { get => flagPowerInduction; set => Set(ref flagPowerInduction, value); }

        #endregion

        /*-------------------------------------------------------------------------------------------------------------------------*/
       
        #region место нагрузки в цепи
        private bool flagPoradokOne = false;
        private bool flagPoradokTwo = true;

        public bool FlagPoradokOne { get => flagPoradokOne; set => Set(ref flagPoradokOne, value); }
        public bool FlagPoradokTwo { get=>flagPoradokTwo; set => Set(ref flagPoradokTwo, value); }
        #endregion

        /*-------------------------------------------------------------------------------------------------------------------------*/

        #region данные о резисторах

        private double resistorOne=0;
        public double ResistorOne { get => resistorOne; set => Set(ref resistorOne, value); }

        private double resistorTwo=0;
        public double ResistorTwo { get => resistorTwo; set => Set(ref resistorTwo, value); }

        #endregion

        /*-------------------------------------------------------------------------------------------------------------------------*/

        #endregion

        #region параметры
       private string oneOne;
           private string oneTwo;
        private string twoOne;
        private string twoTwo;
       
        public string OneOne { get => oneOne; set=>Set(ref oneOne, value); }
        public string OneTwo { get => oneTwo; set => Set(ref oneTwo, value); }
        public string TwoOne { get => twoOne; set => Set(ref twoOne, value); }
        public string TwoTwo { get => twoTwo; set => Set(ref twoTwo, value); }
        /*----------------------------------------------------------------------------------------------------------------------*/

        private bool zParametr = true;
        public bool ZParametr { get => zParametr; set => Set(ref zParametr, value); }

        private bool yParametr ;
        public bool YParametr { get => yParametr; set => Set(ref yParametr, value); }

        private bool aParametr ;
        public bool AParametr { get => aParametr; set => Set(ref aParametr, value); }

        private bool bParametr ;
        public bool BParametr { get => bParametr; set => Set(ref bParametr, value); }

        private bool hParametr ;
        public bool HParametr { get => hParametr; set => Set(ref hParametr, value); }

        private bool gParametr;
        public bool GParametr { get => gParametr; set => Set(ref gParametr, value); }

        #endregion

        #region коэфициенты и параметры зажимов
        private string  resitIn;
        private string resitOut;
        private string amperK;
        private string voltageK;
        private string voltageKDelitel;

        public string ResitIn { get => resitIn; set => Set(ref   resitIn, value); }
        public string ResitOut { get => resitOut; set => Set(ref resitOut, value); }
        public string AmperK { get => amperK; set => Set(ref amperK, value); }
        public string VoltageK { get => voltageK; set => Set(ref voltageK, value); }
        public string VoltageKDelitel { get => voltageKDelitel; set => Set(ref voltageKDelitel, value); }

        #endregion


        /*-------------------------------------------------------------------------------------------------------------------------*/

        #region погрешности
        private double negativResistOne=0;
        private double positivResistOne=0;

        private double negativResistTwo = 0;
        private double positivResistTwo = 0;

        private double negativAmperage = 0;
        private double positivAmperage = 0;

        private double negativVoltage_ExiteOne = 0;
        private double positivVoltage_ExiteOne = 0;

        private double negativVoltage_ExiteTwo = 0;
        private double positivVoltage_ExiteTwo = 0;

        private double negativVoltage = 0;
        private double positivVoltage = 0;

        private double negativCapacit = 0;
        private double positivCapacit = 0;

        private double negativinduction = 0;
        private double positivinduction = 0;

        private double negativResistLoad = 0;
        private double positivResistLoad = 0;

        private double negativPowerActiveOne  = 0;
        private double positivPowerActiveOne = 0;

        private double negativPowerActiveTwo = 0;
        private double positivPowerActiveTwo = 0;

        private double negativPowerLoad = 0;
        private double positivPowerLoad = 0;

        private double negativPowerReactive = 0;
        private double positivPowerReactive = 0;

        private double negativPowerFull = 0;
        private double positivPowerFull = 0;

        private double negativPhase = 0;
        private double positivPhase = 0;

        private double negativResistenLoad = 0;
        private double positivResistenLoad = 0;

        public double NegativResistOne { get => negativResistOne; set => Set(ref negativResistOne, value); }
        public double PositivResistOne { get => positivResistOne; set => Set(ref positivResistOne, value); }
     
        public double NegativResistTwo { get => negativResistTwo; set => Set(ref negativResistTwo, value); }
        public double PositivResistTwo { get => positivResistTwo; set => Set(ref positivResistTwo, value); }

        public double NegativAmperage { get => negativAmperage; set => Set(ref negativAmperage, value); }
        public double PositivAmperage { get => positivAmperage; set => Set(ref positivAmperage, value); }

        public double NegativVoltage_ExiteOne { get => negativVoltage_ExiteOne; set => Set(ref negativVoltage_ExiteOne, value); }
        public double PositivVoltage_ExiteOne { get => positivVoltage_ExiteOne; set => Set(ref positivVoltage_ExiteOne, value); }

        public double NegativVoltage_ExiteTwo { get => negativVoltage_ExiteTwo; set => Set(ref negativVoltage_ExiteTwo, value); }
        public double PositivVoltage_ExiteTwo { get => positivVoltage_ExiteTwo; set => Set(ref positivVoltage_ExiteTwo, value); }

        public double NegativVoltage { get => negativVoltage; set => Set(ref negativVoltage, value); }
        public double PositivVoltage { get => positivVoltage; set => Set(ref positivVoltage, value); }
        
        public double NegativCapacit { get => negativCapacit; set => Set(ref negativCapacit, value); }
        public double PositivCapacit { get => positivCapacit; set => Set(ref positivCapacit, value); }

        public double NegativInduction { get=> negativinduction; set => Set(ref negativinduction, value); }
        public double PositivInduction { get => positivinduction; set=>Set(ref positivinduction, value); }

        public double NegativResistersLoad { get => negativResistLoad; set => Set(ref negativResistLoad, value); }
        public double PositivResistersLoad { get => positivResistLoad; set => Set(ref positivResistLoad, value); }
       
        public double NegativPowerActiveOne { get => negativPowerActiveOne; set => Set(ref negativPowerActiveOne, value); }
        public double PositivPowerActiveOne { get => positivPowerActiveOne; set=>Set(ref positivPowerActiveOne, value); }

        public double NegativPowerActiveTwo { get => negativPowerActiveTwo; set => Set(ref negativPowerActiveTwo, value); }
        public double PositivPowerActiveTwo { get => positivPowerActiveTwo; set => Set(ref positivPowerActiveTwo, value); }

        public double NegativPowerLoad { get => negativPowerLoad; set => Set(ref negativPowerLoad, value); }
        public double PositivPowerLoad { get => positivPowerLoad; set => Set(ref positivPowerLoad, value); }

        public double NegativPowerReactive { get => negativPowerReactive; set => Set(ref negativPowerReactive, value); }
        public double PositivPowerReactive { get => positivPowerReactive; set => Set(ref positivPowerReactive, value); }

        public double NegativPowerFull { get => negativPowerFull; set => Set(ref negativPowerFull, value); }
        public double PositivPowerFull { get => positivPowerFull; set => Set(ref positivPowerFull, value); }

        public double NegativPhase { get => negativPhase; set => Set(ref negativPhase, value); }
        public double PositivPhase { get => positivPhase; set => Set(ref positivPhase, value); }

        public double NegativResistenLoad { get => negativResistenLoad; set => Set(ref negativResistenLoad, value); }
        public double PositivResistenLoad { get => positivResistenLoad; set => Set(ref positivResistenLoad, value); }
        #endregion

        /*-------------------------------------------------------------------------------------------------------------------------*/
        private bool modeConst = true;
        public bool ModeConst { get => modeConst; set => Set(ref modeConst, value); }

        private double pogresh1=0 ;      
         public double Pogresh1 { get => pogresh1; set => Set(ref pogresh1, value); }
              private double pogresh2 = 0;
        public double Pogresh2 { get => pogresh2; set => Set(ref pogresh2, value); }
        private double pogresh3 = 0;
        public double Pogresh3 { get => pogresh3; set => Set(ref pogresh3, value); }
        /*-------------------------------------------------------------------------------------------------------------------------*/

        #region резульаты
        private double amperage = 0;
        private double powerActiveOne = 0;
        private double powerActiveTwo= 0;
        private double powerLoad = 0;
        private double powerReactive = 0;
        private double powerFull = 0;
        private double phaseresultl = 0;
        /*-------------------------------------------------------------------------------------------------------------------------*/

        public double Amperage { get => amperage; set => Set(ref amperage, value); }
        public double PowerActiveOne { get => powerActiveOne; set => Set(ref powerActiveOne, value); }
        public double PowerActiveTwo { get => powerActiveTwo; set => Set(ref powerActiveTwo, value); }
        public double PowerLoad { get => powerLoad; set => Set(ref powerLoad, value); }
        public double PowerFull { get => powerFull; set => Set(ref powerFull, value); }
        public double PowerReactive { get => powerReactive; set => Set(ref powerReactive, value); }
        public double Phaseresultl { get => phaseresultl; set => Set(ref phaseresultl, value); }

        /*-------------------------------------------------------------------------------------------------------------------------*/

      
        private double voltage_exiteOne=0;
        private double voltage_exiteTwo=0;
        public double Voltage_ExiteOne { get=> voltage_exiteOne; set => Set(ref voltage_exiteOne, value); }
        public double Voltage_ExiteTwo { get => voltage_exiteTwo; set => Set(ref voltage_exiteTwo, value); }
      
        
        /*-------------------------------------------------------------------------------------------------------------------------*/
        #endregion

        /*-------------------------------------------------------------------------------------------------------------------------*/
        private string result="";
        public string Result { get => result; set => Set(ref result, value); }

        private string coment = "";
        public string Coment { get => coment; set => Set(ref coment, value); }

        private string comentK = "";
        public string ComentK { get => comentK; set => Set(ref comentK, value); }


        private string charateristks = "";
        public string Charateristks { get => charateristks; set => Set(ref charateristks, value); }

        /*-------------------------------------------------------------------------------------------------------------------------*/

        private string str_voltage = "В";
        private string str_amperage = "А";

        private string str_resister = "Ом";
        private string str_induction = "Гн";
        private string str_capasiti = "Ф";
        

        private string str_powerActive = "Вт";
        private string str_powerLoad= "Вт";
        private string str_poweReactiv = "ВАр";
        private string str_powerFull = "ВА";

        private string str_phase = char.ConvertFromUtf32(176) ;
        private string str_chastota = "Гц";
        /*-------------------------------------------------------------------------------------------------------------------------*/

        public string Str_Voltage { get => str_voltage; set => Set(ref str_voltage, value); }
        public string Str_Resister { get => str_resister; set => Set(ref str_resister, value); }
        public string Str_Amperage { get => str_amperage; set => Set(ref str_amperage, value); }
        public string Str_PowerActive { get => str_powerActive; set => Set(ref str_powerActive, value); }
        public string Str_PowerReactive { get=> str_poweReactiv; set => Set(ref str_poweReactiv, value); }
        public string Str_PowerFull { get => str_powerFull; set => Set(ref str_powerFull, value); }
        public string Str_Phase { get => str_phase; set => Set(ref str_phase, value); }
        public string Str_Chastota { get => str_chastota; set => Set(ref str_chastota, value); }
        public string Str_Induction { get => str_induction; set => Set(ref str_induction, value); }
        public string Str_Capasiti { get => str_capasiti; set => Set(ref str_capasiti, value);}
        public string Str_PowerLoad { get => str_powerLoad; set => Set(ref str_powerLoad, value); }
       

        /*-------------------------------------------------------------------------------------------------------------------------*/

        #region методы
       
        private double ResistCapacity(double C, double F)
        {
            return Math.Round(1/ (2*Math.PI*F*C),3);
        }
        private double ResistInduction(double L, double F)
        {
            return Math.Round(2 * Math.PI * F * L,3);
        }
     
       private Complex FullRessit(Complex r1, Complex r2, Complex Rn, bool f)
        {
         
                if (f) return r1 + (r2 * Rn / (r2 + Rn));
                else return r2 + (r1 * Rn / (r1 + Rn));
            

        }

        private Complex PlechoRessit(Complex r1, Complex r2, Complex Rn, bool f)
        {
            if (f) return  (r2 * Rn / (r2 + Rn));
            else return (r1 * Rn / (r1 + Rn));

        }


        private double Amper(double u, double r)
        {
            return (u / r);
        }



        /*
        private Complex K(Complex A, Complex B, Complex Rn)
        {
            return  A+B/Rn;
        }
        private Complex Ki(Complex C, Complex D, Complex Rn)
        {
            return 1 / (C*Rn+D);
        }
        */
        private Complex NezAparametr(Complex r1,Complex r2, bool f)
        {
            if (f) return r1 / r2 +1;
            else return r2 / r1 +1;
        }
        private Complex NezCParametr(Complex r1,Complex r2, bool f)
        {
            if (!f) return 1 / r1;
            else return 1 / r2;
        }

        private Complex DParametr(Complex r1 , Complex r2, Complex Rn, bool f)
        {
            if(f) return Rn / r2 +1;
            else return Rn  / r1+1;
        }
        private Complex NezBParametr(Complex r1, Complex r2, Complex Rn, bool f)
        {
            if (f) return Rn +r1 +((r1*Rn)/ r2);
            else return Rn + r2 + ((r2 * Rn) / r1);
        }


        #endregion

        #region команды

        private Complex tok, FullResist, plecho, VoltOne, VoltTwo, Power_activeOne, Power_activeTwo, PowerActiveLoad, PowerReactiveLoad, capacity, induction;
        /*------------------------------------------------------------------------------------------------*/
        public ICommand FirstVariantExecution { get; protected set; }

        private bool canFirstVariantExecutionExecute(object p)
        {
           
            if (Voltage.ToString() == "" || ResistorOne.ToString() == "" || ResistorTwo.ToString() == "")
                return false;
            else
            {
                if ((Voltage.ToString() == "0" || ResistorOne.ToString() == "0" || ResistorTwo.ToString() == "0" ) || (FlagPower==true &&LoadCapac == 0 && loadResit == 0 && loadInduc == 0  ) || (FlagChangedPMode == true && Chactota==0))
                return false;
                   return true; 
            }
        }

        private void OnFirstVariantExecutionExecuted(object p)
        {

            FlagOneScript = true;

            double ResitOne = ResistorOne;
            double ResitTwo = ResistorTwo;
            double LoadResitor = LoadResit;

            double Volt = Voltage;
            double Chactots = Chactota;      
            double LoadCapacit = LoadCapac;
            double LoadInduct = LoadInduc;

            switch (Str_Resister)
            {
                case "ТОм":
            
                ResitOne = ResistorOne * Math.Pow(10, 12);
                ResitTwo = ResistorTwo * Math.Pow(10, 12);
                LoadResitor = LoadResit * Math.Pow(10, 12);
            
                    break;

                case "ГОм":
            
                ResitOne = ResistorOne * Math.Pow(10, 9);
                ResitTwo = ResistorTwo * Math.Pow(10, 9);
                LoadResitor = LoadResit * Math.Pow(10, 9);
                    break;



                case "МОм":
            
                ResitOne = ResistorOne * Math.Pow(10, 6);
                ResitTwo = ResistorTwo * Math.Pow(10, 6);
                LoadResitor = LoadResit * Math.Pow(10, 6);
                    break;


                case "кОм":
            
                ResitOne = ResistorOne * Math.Pow(10, 3);
                ResitTwo = ResistorTwo * Math.Pow(10, 3);
                LoadResitor = LoadResit * Math.Pow(10, 3);
                    break;

                case "мОм":
            
                ResitOne = ResistorOne * Math.Pow(10, -3);
                ResitTwo = ResistorTwo * Math.Pow(10, -3);
                LoadResitor = LoadResit * Math.Pow(10, -3);
                    break;


                case "мкОм":
            
                ResitOne = ResistorOne * Math.Pow(10, -6);
                ResitTwo = ResistorTwo * Math.Pow(10, -6);
                LoadResitor = LoadResit * Math.Pow(10, -6);
                    break;
        }
           
            switch (Str_Voltage)
            {
                case"МВ":
                    Volt=Voltage*Math.Pow(10, 6);
                    break;

                case "кВ":
                    Volt = Voltage * Math.Pow(10, 3);
                    break;

                case "мВ":
                    Volt = Voltage * Math.Pow(10, -3);
                    break;

                case "мкВ":
                    Volt = Voltage * Math.Pow(10, -6);
                    break;              
            }
           
            switch (Str_Capasiti)
            {
                case "мФ":
                    LoadCapacit = LoadCapac * Math.Pow(10, -3);
                    break;

                case "мкФ":
                    LoadCapacit = LoadCapac * Math.Pow(10, -6);
                    break;

                case "нФ":
                    LoadCapacit = LoadCapac * Math.Pow(10, -9);
                    break;

                case "пФ":
                    LoadCapacit = LoadCapac * Math.Pow(10, -12);
                    break;
            }

            switch (Str_Chastota)
            {
                case "ГГц":
                    Chactots = Chactota * Math.Pow(10, 9);
                    break;

                case "МГц":
                    Chactots = Chactota * Math.Pow(10, 6);
                    break;

                case "кГц":
                    Chactots = Chactota * Math.Pow(10, 3);
                    break;

                case "мГц":
                    Chactots = Chactota * Math.Pow(10, -3);
                    break;

                case "мкГГц":
                    Chactots = Chactota * Math.Pow(10, -6);
                    break;
            }

            switch (Str_Induction)
            {
                case "мГн":
                    LoadInduct = LoadInduc * Math.Pow(10, -3);
                    break;

                case "мкГн":
                    LoadInduct = LoadInduc * Math.Pow(10, -6);
                    break;

                case "нГн":
                    LoadInduct = LoadInduc * Math.Pow(10, -9);
                    break;

            
            }

            FlagOneScript = true;

            if (FlagChangedConstMode == true)
            {
                PowerReactive = 0;

                if (FlagPower)
                {


                    if (FlagPowerRessit)
                    {
                        if (loadResit == 0) MessageBox.Show("сопротивление нагрузки равно 0");
                        else
                        {
                            plecho = PlechoRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0), Complex.FromPolarCoordinates(LoadResitor, 0), flagPoradokTwo);
                            FullResist = FullRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0), Complex.FromPolarCoordinates(LoadResitor, 0), flagPoradokTwo);
                            tok = Complex.FromPolarCoordinates(Volt, 0) / FullResist;
                            Amperage = Math.Round(tok.Magnitude, 3);
                 
                            if (FlagPoradokTwo)
                            {
                                VoltTwo = tok * plecho;
                                VoltOne = tok * Complex.FromPolarCoordinates(ResitOne, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(tok) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(VoltTwo / Complex.FromPolarCoordinates(ResitTwo, 0)) * VoltTwo;
                                PowerActiveLoad = Complex.Conjugate(VoltTwo / Complex.FromPolarCoordinates(LoadResitor, 0)) * VoltTwo;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                                PowerLoad = Math.Round(PowerActiveLoad.Magnitude, 3);

                                Result =
                                     " Ur1≈" + Voltage_ExiteOne + str_voltage
                                    + ", Ur2≈" + Voltage_ExiteTwo + str_voltage
                                    + ", URн≈" + Voltage_ExiteTwo + str_voltage
                                    + ", IRн≈" + Math.Round(Voltage_ExiteTwo * (1 / Complex.FromPolarCoordinates(LoadResitor, 0)).Magnitude, 3)
                                    + ", IR2≈" + Math.Round(Voltage_ExiteTwo * (1 / Complex.FromPolarCoordinates(ResitTwo, 0)).Magnitude, 3)
                                    + ", IR1≈" + amperage + str_amperage;
                                Coment = "";
                            }

                            else
                            {
                                VoltOne = tok * plecho;
                                VoltTwo = tok * Complex.FromPolarCoordinates(ResitTwo, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude , 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(VoltOne / Complex.FromPolarCoordinates(ResitOne, 0)) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(tok) * VoltTwo;
                                PowerActiveLoad = Complex.Conjugate(VoltOne / Complex.FromPolarCoordinates(LoadResitor, 0)) * VoltOne;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                                PowerLoad = Math.Round(PowerActiveLoad.Magnitude, 3);

                                Result =
                                     " Ur1≈" + Voltage_ExiteOne + str_voltage
                                    + ", Ur2≈" + Voltage_ExiteTwo + str_voltage
                                    + ", URн≈" + Voltage_ExiteOne + str_voltage
                                    + ", IRн≈" + Math.Round(voltage_exiteOne * (1 / Complex.FromPolarCoordinates(LoadResitor, 0)).Magnitude, 3)
                                    + ", IR2≈" + amperage + str_amperage
                                    + ", IR1≈" + Math.Round(voltage_exiteOne * (1 / Complex.FromPolarCoordinates(ResitOne, 0)).Magnitude, 3);
                                Coment = "";
                            }

                            PowerFull =Math.Round( (PowerActiveOne + PowerActiveTwo +PowerActiveLoad).Magnitude,3);
                        }
                    }
                    if (FlagPowerCapacity) MessageBox.Show("не влияет");
                    if (FlagPowerInduction) MessageBox.Show("не влияет");



                }

                else
                {
                    
                    PowerLoad = 0;
                    Amperage = Math.Round(Amper(Volt, ResitTwo + ResitOne), 3);

                    Voltage_ExiteOne = Math.Round(Amper(Volt, ResitTwo + ResitOne) * ResitOne, 3);
                    Voltage_ExiteTwo = Math.Round(Amper(Volt, ResitTwo + ResitOne) * ResitTwo, 3);

                    PowerActiveTwo = Math.Round(Amperage * Voltage_ExiteTwo, 3);
                    PowerActiveOne = Math.Round(Amperage * Voltage_ExiteOne, 3);
                    PowerFull = (PowerActiveOne + PowerActiveTwo);

                    Result = "I≈ " + amperage + str_amperage
                        + ", Ur1≈" + Math.Round((amperage * ResitOne), 3) + str_voltage
                        + ", Ur2≈" + Math.Round((amperage * ResitTwo), 3) + str_voltage;
                    Coment = "";
                }

                switch (Str_Amperage)
                {
                    case "МА":
                        Amperage /= Math.Pow(10, 6);
                        break;

                    case "кА":
                        Amperage /= Math.Pow(10, 3);
                        break;

                    case "мА":
                        Amperage /= Math.Pow(10, -3);
                        break;

                    case "мкА":
                        Amperage /= Math.Pow(10, -6);
                        break;
                }
                switch (Str_PowerActive)
                {


                    case "ГВт":

                        PowerActiveOne /= Math.Pow(10, 9);
                        PowerActiveTwo /= Math.Pow(10, 9);
                        PowerLoad /= Math.Pow(10, 9);
                        break;



                    case "МВт":

                        PowerActiveOne /= Math.Pow(10, 6);
                        PowerActiveTwo /= Math.Pow(10, 6);
                        PowerLoad /= Math.Pow(10, 6);
                        break;


                    case "кВт":

                        PowerActiveOne /= Math.Pow(10, 3);
                        PowerActiveTwo /= Math.Pow(10, 3);
                        PowerLoad /= Math.Pow(10, 3);
                        break;

                    case "мВт":

                        PowerActiveOne /= Math.Pow(10, -3);
                        PowerActiveTwo /= Math.Pow(10, -3);
                        PowerLoad /= Math.Pow(10, -3);
                        break;


                    case "мкВт":

                        PowerActiveOne /= Math.Pow(10, -6);
                        PowerActiveTwo /= Math.Pow(10, -6);
                        PowerLoad /= Math.Pow(10, -6);
                        break;
                }
                switch (Str_PowerFull)
                {
                    case "ГВА":

                        PowerFull /= Math.Pow(10, 9);


                        break;

                    case "МВА":
                        PowerFull /= Math.Pow(10, 6);

                        break;



                    case "кВА":

                        PowerFull /= Math.Pow(10, 3);
                        break;


                    case "мВА":

                        PowerFull /= Math.Pow(10, -3);
                        break;

                    case "мкВА":
                        PowerFull /= Math.Pow(10, -6);

                        break;
                    case "нВА":
                        PowerFull /= Math.Pow(10, -9);

                        break;
                }
                switch (Str_PowerReactive)
                {
                    case "ГВАр":

                        PowerReactive /= Math.Pow(10, 9);


                        break;

                    case "МВАр":
                        PowerReactive /= Math.Pow(10, 6);

                        break;



                    case "кВАр":

                        PowerReactive /= Math.Pow(10, 3);
                        break;


                    case "мВАр":

                        PowerReactive /= Math.Pow(10, -3);
                        break;

                    case "мкВАр":
                        PowerFull /= Math.Pow(10, -6);

                        break;
                    case "нВАр":
                        PowerReactive /= Math.Pow(10, -9);

                        break;
                }                      
             }


            if (FlagChangedPMode == true)
            {
                if (PhaseNegativ) Phase *= -1;
            if(PhasePositiv && Phase<0) Phase *= -1;        
            
                Complex signal = Complex.FromPolarCoordinates(Volt, Phase * Math.PI / 180);

                if (FlagPower  )
                {                 

                    if (FlagPowerRessit)
                    {
                        PowerReactive = 0;
                        if (LoadResit == 0) MessageBox.Show("Сопротивление не задано");
                        else
                        {
                            plecho = PlechoRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0), Complex.FromPolarCoordinates(LoadResitor, 0), flagPoradokTwo);
                            FullResist = FullRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0), Complex.FromPolarCoordinates(LoadResitor, 0), flagPoradokTwo);
                            tok = signal / FullResist;
                            Amperage = Math.Round(tok.Magnitude, 3);

                            if (FlagPoradokTwo)
                            {
                                VoltTwo = tok * plecho;
                                VoltOne = tok * Complex.FromPolarCoordinates(ResitOne, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(tok) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(VoltTwo / Complex.FromPolarCoordinates(ResitTwo, 0)) * VoltTwo;
                                PowerActiveLoad = Complex.Conjugate(VoltTwo / Complex.FromPolarCoordinates(LoadResitor, 0)) * VoltTwo;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                                PowerLoad = Math.Round(PowerActiveLoad.Magnitude, 3);

                                PowerFull = Math.Round((Complex.Conjugate(tok) * signal).Magnitude, 3);

                                Phaseresultl = VoltTwo.Phase * 180 / Math.PI;

                                Result =
                        " Ur1≈" + "(" + Math.Round(Voltage_ExiteOne, 3) + " ; " + VoltOne.Phase * 180 / Math.PI + ")" + str_voltage
                        + ", Ur2≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + VoltTwo.Phase * 180 / Math.PI + ")" + str_voltage
                        + ", URн≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + VoltTwo.Phase * 180 / Math.PI + ")" + str_voltage
                        + ", IR1≈" + "(" + Math.Round(Amperage, 3) + " ; " + tok.Phase * 180 / Math.PI + ")" + Str_Amperage
                        + ", IR2≈" + "(" + Math.Round((VoltTwo * (1 / Complex.FromPolarCoordinates(ResitTwo, 0))).Magnitude, 3) + " ; " + (VoltTwo * (1 / Complex.FromPolarCoordinates(ResitTwo, 0))).Phase * 180 / Math.PI + ")" + Str_Amperage
                        + ", IRн≈" + "(" + Math.Round((VoltTwo * (1 / Complex.FromPolarCoordinates(LoadResitor, 0))).Magnitude, 3) + " ; " + Math.Round((VoltTwo * (1 / Complex.FromPolarCoordinates(LoadResitor, 0))).Phase * 180 / Math.PI, 3) + ")" + Str_Amperage;
                                Coment = "данные данны в полярной форме записи";

                            }

                            else
                            {
                                VoltOne = tok * plecho;
                                VoltTwo = tok * Complex.FromPolarCoordinates(ResitTwo, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(VoltOne / Complex.FromPolarCoordinates(ResitOne, 0)) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(tok) * VoltTwo;
                                PowerActiveLoad = Complex.Conjugate(VoltOne / Complex.FromPolarCoordinates(LoadResitor, 0)) * VoltOne;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                                PowerLoad = Math.Round(PowerActiveLoad.Magnitude, 3);

                                PowerFull = Math.Round((Complex.Conjugate(tok) * signal).Magnitude, 3);

                                Phaseresultl = VoltOne.Phase * 180 / Math.PI;

                                Result =
                         " Ur1≈" + "(" + Math.Round(Voltage_ExiteOne, 3) + " ; " + VoltOne.Phase * 180 / Math.PI + ")" + str_voltage
                        + ", Ur2≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + VoltTwo.Phase * 180 / Math.PI + ")" + str_voltage
                        + ", URн≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + VoltTwo.Phase * 180 / Math.PI + ")" + str_voltage
                        + ", IR2≈" + "(" + Math.Round(Amperage, 3) + " ; " + tok.Phase * 180 / Math.PI + ")" + Str_Amperage
                        + ", IR1≈" + "(" + Math.Round((VoltOne * (1 / Complex.FromPolarCoordinates(ResitOne, 0))).Magnitude, 3) + " ; " + (VoltOne * (1 / Complex.FromPolarCoordinates(ResitOne, 0))).Phase * 180 / Math.PI + ")" + Str_Amperage
                        + ", IRн≈" + "(" + Math.Round((VoltOne.Magnitude * (1 / Complex.FromPolarCoordinates(LoadResitor, 0))).Magnitude, 3) + " ; " + Math.Round((VoltOne.Magnitude * (1 / Complex.FromPolarCoordinates(LoadResitor, 0))).Phase * 180 / Math.PI, 3) + ")" + Str_Amperage;
                                Coment = "данные данны в полярной форме записи";
                            }
                        }                     
                    }

                    if (FlagPowerCapacity)
                    {

                        PowerLoad = 0;
                        if (LoadCapacit == 0) MessageBox.Show("нулевое значение  ёмкости");
                        
                        else
                        {
                            capacity= new Complex(0, -ResistCapacity(LoadCapacit, Chactots));

                            plecho = PlechoRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0),capacity, flagPoradokTwo);
                            FullResist = FullRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0), capacity, flagPoradokTwo);
                            tok = signal / FullResist;
                            Amperage = Math.Round(tok.Magnitude, 3);

                            if (FlagPoradokTwo)
                            {
                                VoltTwo = tok * plecho;
                                VoltOne = tok * Complex.FromPolarCoordinates(ResitOne, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(tok) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(VoltTwo / Complex.FromPolarCoordinates(ResitTwo, 0)) * VoltTwo;
                               PowerReactiveLoad = Complex.Conjugate(VoltTwo / capacity) * VoltTwo;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                               PowerReactive = Math.Round(PowerReactiveLoad.Magnitude, 3);

                                PowerFull = Math.Round((Complex.Conjugate(tok) * signal).Magnitude, 3);

                                Phaseresultl = Math.Round(VoltTwo.Phase * 180 / Math.PI, 2);

                                Result =
                        " Ur1≈" + "(" + Math.Round(Voltage_ExiteOne, 3) + " ; " + Math.Round(VoltOne.Phase * 180 / Math.PI,2) + ")" + str_voltage
                        + ", Ur2≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI,2) + ")" + str_voltage
                        + ", Uc≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI,2) + ")" + str_voltage
                        + ", IR1≈" + "(" + Math.Round(Amperage, 3) + " ; " + Math.Round(((1/ Complex.FromPolarCoordinates(ResitOne, 0)) *VoltOne).Phase * 180 / Math.PI,2) + ")" + Str_Amperage
                        + ", IR2≈" + "(" + Math.Round((VoltTwo * (1 / Complex.FromPolarCoordinates(ResitTwo, 0))).Magnitude, 3) + " ; " + Math.Round((VoltTwo * (1 / Complex.FromPolarCoordinates(ResitTwo, 0))).Phase * 180 / Math.PI,2) + ")" + Str_Amperage
                        + ", Ic≈" + "(" + Math.Round((VoltTwo * (1 / capacity)).Magnitude, 3) + " ; " + Math.Round((VoltTwo * (1 / capacity)).Phase * 180 / Math.PI ,2) + ")" + Str_Amperage;

                                Coment = "данные данны в полярной форме записи. Конденсатор брать с номинальным напряжением от "+Math.Round(Voltage_ExiteTwo*Math.Sqrt(2),3)+ Str_Voltage;
                            }

                            else
                            {
                                VoltOne = tok * plecho;
                                VoltTwo = tok * Complex.FromPolarCoordinates(ResitTwo, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(VoltOne / Complex.FromPolarCoordinates(ResitOne, 0)) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(tok) * VoltTwo;
                               PowerReactiveLoad = Complex.Conjugate(VoltOne / capacity) * VoltOne;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                                PowerReactive = Math.Round(PowerReactiveLoad.Magnitude, 3);

                                PowerFull = Math.Round((Complex.Conjugate(tok) * signal).Magnitude, 3);

                                Phaseresultl = Math.Round(VoltOne.Phase * 180 / Math.PI,2);

                                Result =
                         " Ur1≈" + "(" + Math.Round(Voltage_ExiteOne, 3) + " ; " + Math.Round(VoltOne.Phase * 180 / Math.PI,2) + ")" + str_voltage
                        + ", Ur2≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI,2) + ")" + str_voltage
                        + ", Uc≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI,2) + ")" + str_voltage
                        + ", IR2≈" + "(" + Math.Round(Amperage, 3) + " ; " + Math.Round(((1 / Complex.FromPolarCoordinates(ResitTwo, 0)) * VoltTwo).Phase * 180 / Math.PI,2) + ")" + Str_Amperage
                        + ", IR1≈" + "(" + Math.Round((VoltOne * (1 / Complex.FromPolarCoordinates(ResitOne, 0))).Magnitude, 3) + " ; " + Math.Round((VoltOne * (1 / Complex.FromPolarCoordinates(ResitOne, 0))).Phase * 180 / Math.PI,2) + ")" + Str_Amperage
                        + ", Ic≈" + "(" + Math.Round((VoltOne * (1 / capacity)).Magnitude, 3) + " ; " + Math.Round((VoltOne * (1 / capacity)).Phase * 180 / Math.PI,2) + ")" + Str_Amperage;

                                Coment = "данные данны в полярной форме записи.  Конденсатор брать с номинальным напряжением от "+Math.Round(Voltage_ExiteOne*Math.Sqrt(2),3)+Str_Voltage;
                            }

                        }
                    }

                    if (FlagPowerInduction)
                    {
                        PowerLoad = 0;

                        if (LoadInduct == 0) MessageBox.Show("нулевое значение  индуктивности");
                        else
                        {
                            induction = new Complex(0, ResistInduction(LoadInduct, Chactots));
                            plecho = PlechoRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0), induction, flagPoradokTwo);
                            FullResist = FullRessit(Complex.FromPolarCoordinates(ResitOne, 0), Complex.FromPolarCoordinates(ResitTwo, 0), induction, flagPoradokTwo);
                            tok =signal / FullResist;
                            Amperage = Math.Round(tok.Magnitude, 3);

                            if (FlagPoradokTwo)
                            {
                                VoltTwo = tok * plecho;
                                VoltOne = tok * Complex.FromPolarCoordinates(ResitOne, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(tok) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(VoltTwo / Complex.FromPolarCoordinates(ResitTwo, 0)) * VoltTwo;
                                PowerReactiveLoad = Complex.Conjugate(VoltTwo / induction) * VoltTwo;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                                PowerReactive = Math.Round(PowerReactiveLoad.Magnitude, 3);

                                PowerFull = Math.Round((Complex.Conjugate(tok) * signal).Magnitude, 3);

                                Phaseresultl = Math.Round(VoltTwo.Phase * 180 / Math.PI,2);

                                Result =
                        " Ur1≈" + "(" + Math.Round(Voltage_ExiteOne, 3) + " ; " + Math.Round(VoltOne.Phase * 180 / Math.PI, 2) + ")" + str_voltage
                        + ", Ur2≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI, 2) + ")" + str_voltage
                        + ", UL≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI, 2) + ")" + str_voltage
                        + ", IR1≈" + "(" + Math.Round(Amperage, 3) + " ; " + Math.Round(((1 / Complex.FromPolarCoordinates(ResitOne, 0)) * VoltOne).Phase * 180 / Math.PI, 2) + ")" + Str_Amperage
                        + ", IR2≈" + "(" + Math.Round((VoltTwo * (1 / Complex.FromPolarCoordinates(ResitTwo, 0))).Magnitude, 3) + " ; " + Math.Round((VoltTwo * (1 / Complex.FromPolarCoordinates(ResitTwo, 0))).Phase * 180 / Math.PI, 2) + ")" + Str_Amperage
                        + ", IL≈" + "(" + Math.Round((VoltTwo * (1 / induction)).Magnitude, 3) + " ; " + Math.Round((VoltTwo * (1 / induction)).Phase * 180 / Math.PI, 2) + ")" + Str_Amperage;

                                Coment = "данные данны в полярной форме записи";
                            }

                            else
                            {
                                VoltOne = tok * plecho;
                                VoltTwo = tok * Complex.FromPolarCoordinates(ResitTwo, 0);

                                Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3);
                                Voltage_ExiteTwo = Math.Round(VoltTwo.Magnitude, 3);

                                Power_activeOne = Complex.Conjugate(VoltOne / Complex.FromPolarCoordinates(ResitOne, 0)) * VoltOne;
                                Power_activeTwo = Complex.Conjugate(tok) * VoltTwo;
                                PowerReactiveLoad = Complex.Conjugate(VoltOne / induction) * VoltOne;

                                PowerActiveOne = Math.Round(Power_activeOne.Magnitude, 3);
                                PowerActiveTwo = Math.Round(Power_activeTwo.Magnitude, 3);
                                PowerReactive = Math.Round(PowerReactiveLoad.Magnitude, 3);

                                PowerFull = Math.Round((Complex.Conjugate(tok) * signal).Magnitude, 3);

                                Phaseresultl = Math.Round(VoltOne.Phase * 180 / Math.PI,2);

                                Result =
                         " Ur1≈" + "(" + Math.Round(Voltage_ExiteOne, 3) + " ; " + Math.Round(VoltOne.Phase * 180 / Math.PI, 2) + ")" + str_voltage
                        + ", Ur2≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI, 2) + ")" + str_voltage
                        + ", UL≈" + "(" + Math.Round(Voltage_ExiteTwo, 3) + " ; " + Math.Round(VoltTwo.Phase * 180 / Math.PI, 2) + ")" + str_voltage
                        + ", IR2≈" + "(" + Math.Round(Amperage, 3) + " ; " + Math.Round(((1 / Complex.FromPolarCoordinates(ResitTwo, 0)) * VoltTwo).Phase * 180 / Math.PI, 2) + ")" + Str_Amperage
                        + ", IR1≈" + "(" + Math.Round((VoltOne * (1 / Complex.FromPolarCoordinates(ResitOne, 0))).Magnitude, 3) + " ; " + Math.Round((VoltOne * (1 / Complex.FromPolarCoordinates(ResitOne, 0))).Phase * 180 / Math.PI, 2) + ")" + Str_Amperage
                        + ", IL≈" + "(" + Math.Round((VoltOne * (1 /induction)).Magnitude, 3) + " ; " + Math.Round((VoltOne * (1 / induction)).Phase * 180 / Math.PI, 2) + ")" + Str_Amperage;

                                Coment = "данные данны в полярной форме записи";
                            }
                        }
                    }
                }
                else
                {
                    PowerReactive = 0;
                    PowerLoad = 0;
                     FullResist = new Complex(ResitOne + ResitTwo, 0);
                 
                    tok = Complex.Divide(signal, FullResist);
                    Amperage = Math.Round(tok.Magnitude, 3);

                  VoltOne = Complex.Multiply(Complex.Divide(signal, FullResist), Complex.FromPolarCoordinates(ResitOne,0)  );
                    Voltage_ExiteOne = Math.Round(VoltOne.Magnitude, 3 );

                  VoltTwo = Complex.Multiply(Complex.Divide(signal, FullResist), Complex.FromPolarCoordinates(ResitTwo, 0)) ;
                    Voltage_ExiteTwo = Math.Round (VoltTwo.Magnitude, 3 );

                    PowerActiveOne = Math.Round (Complex.Multiply(VoltOne , Complex.Conjugate(tok)).Magnitude,3);
                    PowerActiveTwo = Math.Round(Complex.Multiply(VoltTwo, Complex.Conjugate(tok)).Magnitude,3 );
                     PowerFull = Math.Round(Complex.Multiply(Complex.Conjugate(tok), signal).Magnitude, 3);

                    Phaseresultl = VoltTwo.Phase*180/Math.PI;

                   

                    Result = "I≈ " +"("+ amperage+" ; "+ tok.Phase * 180 / Math.PI + ")" + str_amperage
                       + ", Ur1≈" + "(" + Voltage_ExiteOne+" ; " + VoltOne.Phase * 180 / Math.PI+")" + str_voltage
                       + ", Ur2≈" + "(" + Voltage_ExiteTwo + " ; " + VoltTwo.Phase * 180 / Math.PI + ")" + str_voltage;
                   
                    Coment = "данные данны в полярной форме записи";
                }

                switch (Str_Amperage)
                {
                    case "МА":
                        Amperage /= Math.Pow(10, 6);
                        break;

                    case "кА":
                        Amperage /= Math.Pow(10, 3);
                        break;

                    case "мА":
                        Amperage /= Math.Pow(10, -3);
                        break;

                    case "мкА":
                        Amperage /= Math.Pow(10, -6);
                        break;
                }
                switch (Str_PowerActive)
                {


                    case "ГВт":

                        PowerActiveOne /= Math.Pow(10, 9);
                        PowerActiveTwo /= Math.Pow(10, 9);
                        PowerLoad /= Math.Pow(10, 9);
                        break;



                    case "МВт":

                        PowerActiveOne /= Math.Pow(10, 6);
                        PowerActiveTwo /= Math.Pow(10, 6);
                        PowerLoad /= Math.Pow(10, 6);
                        break;


                    case "кВт":

                        PowerActiveOne /= Math.Pow(10, 3);
                        PowerActiveTwo /= Math.Pow(10, 3);
                        PowerLoad /= Math.Pow(10, 3);
                        break;

                    case "мВт":

                        PowerActiveOne /= Math.Pow(10, -3);
                        PowerActiveTwo /= Math.Pow(10, -3);
                        PowerLoad /= Math.Pow(10, -3);
                        break;


                    case "мкВт":

                        PowerActiveOne /= Math.Pow(10, -6);
                        PowerActiveTwo /= Math.Pow(10, -6);
                        PowerLoad /= Math.Pow(10, -6);
                        break;
                }
                switch (Str_PowerFull)
                {
                    case "ГВА":

                        PowerFull /= Math.Pow(10, 9);


                        break;

                    case "МВА":
                        PowerFull /= Math.Pow(10, 6);

                        break;



                    case "кВА":

                        PowerFull /= Math.Pow(10, 3);
                        break;


                    case "мВА":

                        PowerFull /= Math.Pow(10, -3);
                        break;

                    case "мкВА":
                        PowerFull /= Math.Pow(10, -6);

                        break;
                    case "нВА":
                        PowerFull /= Math.Pow(10, -9);

                        break;
                }
                switch (Str_PowerReactive)
                {
                    case "ГВАр":

                        PowerReactive /= Math.Pow(10, 9);


                        break;

                    case "МВАр":
                        PowerReactive /= Math.Pow(10, 6);

                        break;



                    case "кВАр":

                        PowerReactive /= Math.Pow(10, 3);
                        break;


                    case "мВАр":

                        PowerReactive /= Math.Pow(10, -3);
                        break;

                    case "мкВАр":
                        PowerFull /= Math.Pow(10, -6);

                        break;
                    case "нВАр":
                        PowerReactive /= Math.Pow(10, -9);

                        break;
                }
            }
           
        }
        /*------------------------------------------------------------------------------------------------*/


        /*------------------------------------------------------------------------------------------------*/
        public ICommand PogreshComand { get; protected set; }

        private bool canPogreshComandExecute(object p)
        {
            if (FlagOneScript)
            {
                if ((pogresh1 < 0 || pogresh1 > 100) || (pogresh2 < 0 || pogresh2 > 100) || (pogresh3 < 0 || pogresh3 > 100)) return false;
                return true;
            }
            return false;
      
        }
    
        private void OnPogreshComandExecuted(object p)
        {
            double AbsPOne, AbsPTwo, AbsPThere;
            double RelativPOne, RelativPTwo, RelativPThere;
            double PPlecho = 0, PTok=0, PFull=0, PVoltOne=0, PVoltTwo=0 , PPowerOne=0, PPowerTwo=0,PPowerActiveLoad=0, PPowerReactiveLoad=0;

            if(Chactota==0 || FlagChangedConstMode)
            {
                capacity = 0;
                induction = 0;
            }

            NegativResistOne = Math.Round(ResistorOne - (ResistorOne  / 100) * pogresh1, 3);
            PositivResistOne = Math.Round(ResistorOne + (ResistorOne / 100) * pogresh1, 3);

            AbsPOne = (ResistorOne / 100) * pogresh1;
            RelativPOne = pogresh1 / 100;

           NegativResistTwo = Math.Round(ResistorTwo - (ResistorTwo  / 100) * pogresh2, 3);
            PositivResistTwo = Math.Round(ResistorTwo + (ResistorTwo / 100) * pogresh2, 3);
            AbsPTwo = (ResistorTwo / 100) * pogresh2;
            RelativPTwo = pogresh2 / 100;


            PFull = AbsPOne + AbsPTwo;

            PTok = (PFull * Complex.Pow(FullResist, -1)).Magnitude + 0;

            PVoltTwo = PTok + RelativPTwo;
            PVoltOne = PTok + RelativPOne;
        
           PPowerOne = PTok  + PVoltOne;
           PPowerTwo= PTok  + PVoltTwo;

         
            if (FlagPower)
            {
                RelativPThere = pogresh3 / 100;
               
                if (FlagPowerRessit)
                {
                    NegativResistenLoad = Math.Round(LoadResit - (LoadResit / 100)*pogresh3, 3);
                    PositivResistenLoad = Math.Round(LoadResit + (LoadResit / 100) * pogresh3, 3);
                   
                    AbsPThere = (LoadResit / 100) * pogresh3;

                    if (FlagPoradokTwo)
                    {
                        PPlecho = RelativPThere + RelativPTwo + (AbsPTwo + AbsPThere) / (ResistorTwo +LoadResit);
                       
                        PFull = (PPlecho * plecho).Magnitude + AbsPOne;

                        PTok = (PFull * Complex.Pow(FullResist, -1)).Magnitude + 0;

                        PVoltOne = PTok  + RelativPOne;
                        PVoltTwo = PTok  + PPlecho;
                        PPowerActiveLoad = PVoltTwo + PTok;

                    }
                    else
                    {
                        PPlecho = RelativPThere + RelativPTwo + (AbsPTwo + AbsPThere) / (ResistorOne + LoadResit);
                      
                        PFull = (PPlecho * plecho).Magnitude + AbsPTwo;

                        PTok = (PFull * Complex.Pow(FullResist, -1)).Magnitude + 0;

                        PVoltTwo = PTok  + RelativPTwo;
                        PVoltOne = PTok  + PPlecho;
                        PPowerActiveLoad = PVoltOne + PTok;

                    }
                    NegativCapacit = 0;
                    PositivCapacit = 0;
                    NegativInduction = 0;
                    PositivInduction = 0;
                }

                if (FlagPowerCapacity)
                {
                    NegativInduction = 0;
                    PositivInduction =0;
                    NegativResistenLoad =0;
                    PositivResistenLoad = 0;

                    NegativCapacit = Math.Round((capacity - (capacity / 100) * Pogresh3).Magnitude, 3);
                    PositivCapacit = Math.Round((capacity + (capacity / 100) * Pogresh3).Magnitude, 3);
                  
                    AbsPThere = ((capacity / 100) * pogresh3).Magnitude;
                    if (FlagPoradokTwo)
                    {
                        PPlecho = (RelativPThere + RelativPTwo +( AbsPTwo + AbsPThere)/(ResistorTwo+capacity)).Magnitude;
                      
                        PFull = (PPlecho * plecho).Magnitude + AbsPOne;

                        PTok = (PFull * Complex.Pow(FullResist, -1)).Magnitude + 0;

                        PVoltOne = PTok  + RelativPOne;
                        PVoltTwo = PTok  + PPlecho;
                        PPowerReactiveLoad = PVoltTwo + PTok;

                    }
                    else
                    {
                        PPlecho = (RelativPThere + RelativPTwo + (AbsPTwo + AbsPThere) / (ResistorOne + capacity)).Magnitude;
                       
                        PFull = (PPlecho * plecho).Magnitude + AbsPTwo;

                        PTok = (PFull * Complex.Pow(FullResist, -1)).Magnitude + 0;

                        PVoltTwo = PTok  + RelativPTwo;
                        PVoltOne = PTok  + PPlecho;
                        PPowerReactiveLoad = PVoltOne + PTok;
                
                    }
                  
                }

                if (FlagPowerInduction)
                {
                    NegativInduction = Math.Round((induction - (induction  / 100) * Pogresh3).Magnitude, 3);
                    PositivInduction = Math.Round((induction + (induction / 100) * Pogresh3).Magnitude, 3);

                    AbsPThere = ((capacity / 100) * pogresh3).Magnitude;
                    if (FlagPoradokTwo)
                    {
                        PPlecho = (RelativPThere + RelativPTwo + (AbsPTwo + AbsPThere) / (ResistorTwo + induction)).Magnitude;
                        
                        PFull = (PPlecho * plecho).Magnitude + AbsPOne;

                        PTok = (PFull * Complex.Pow(FullResist, -1)).Magnitude + 0;

                        PVoltOne = PTok + RelativPOne;
                        PVoltTwo = PTok  + PPlecho;
                        PPowerReactiveLoad = PVoltTwo + PTok;

                    }
                    else
                    {
                        PPlecho = (RelativPThere + RelativPTwo + (AbsPTwo + AbsPThere) / (ResistorOne + induction)).Magnitude;
                      
                        PFull = (PPlecho * plecho).Magnitude + AbsPTwo;

                        PTok = (PFull * Complex.Pow(FullResist, -1)).Magnitude + 0;

                        PVoltTwo = PTok + RelativPTwo;
                        PVoltOne = PTok  + PPlecho;
                        PPowerReactiveLoad = PVoltOne + PTok;      

                    }
                    NegativCapacit = 0;
                    PositivCapacit = 0 ;
                    NegativResistenLoad = 0;
                    PositivResistenLoad = 0;

                 
                
                }

            }
          if(FlagChangedPMode)
            {
                if (FlagPoradokTwo)
                {
                    NegativPhase = (VoltTwo - PVoltTwo * VoltTwo).Phase * 180 / Math.PI;
                    PositivPhase = (VoltTwo + PVoltTwo * VoltTwo).Phase * 180 / Math.PI;
                }
                else
                {
                    NegativPhase = (VoltOne - PVoltTwo * VoltOne).Phase * 180 / Math.PI;
                    PositivPhase = (VoltOne + PVoltTwo * VoltOne).Phase * 180 / Math.PI;
                }
            }
             

           NegativAmperage = Amperage - PTok * Amperage;
            PositivAmperage = Amperage+PTok*Amperage;

            NegativVoltage_ExiteOne = Voltage_ExiteOne - PVoltOne * Voltage_ExiteOne;
            PositivVoltage_ExiteOne = Voltage_ExiteOne + PVoltOne * Voltage_ExiteOne;

            NegativVoltage_ExiteTwo = Voltage_ExiteTwo - PVoltTwo * Voltage_ExiteTwo;
            PositivVoltage_ExiteTwo = Voltage_ExiteTwo + PVoltTwo * Voltage_ExiteTwo;

            NegativPowerActiveOne = PowerActiveOne - PPowerOne * PowerActiveTwo;
            PositivPowerActiveOne = PowerActiveOne + PPowerOne * PowerActiveTwo;

            NegativPowerActiveTwo = PowerActiveTwo - PPowerTwo * PowerActiveTwo;
            PositivPowerActiveTwo = PowerActiveTwo + PPowerTwo * PowerActiveTwo;

            NegativPowerLoad = PowerLoad - PPowerActiveLoad * PowerLoad;
          PositivPowerLoad = PowerLoad + PPowerActiveLoad * PowerLoad;

            NegativPowerReactive = PowerReactive - PPowerReactiveLoad * PowerReactive;
            PositivPowerReactive = PowerReactive + PPowerReactiveLoad * PowerReactive;

            /*------------------------------------------------------------------------*/
            NegativPowerFull = PowerFull - (PTok+0) * PowerFull;
            PositivPowerFull = PowerFull + (PTok + 0) * PowerFull;
            /*-------------------------------------------------------------------*/


        }

        /*------------------------------------------------------------------------------------------------*/

        public ICommand CommandParametrs { get;protected set; }
        private bool canCommandParametrsExecute(object p)
        {
               if ( ResistorOne.ToString() == "" || ResistorTwo.ToString() == "")
                return false;
            else
            {
                
                if (((ResistorOne.ToString() == "0" || ResistorTwo.ToString() == "0" ) || (FlagPower==true &&LoadCapac == 0 && loadResit == 0 && loadInduc == 0) || (FlagChangedPMode == true && Chactota==0)))
                return false;
                   return true; 
            }
        }
        private void OnCommandParametrsExecuted(object p)
        {
            
            Complex A, B = 0, C, D = 0, DET;

            Complex Resist1 = new Complex(ResistorOne, 0);
            Complex Resist2 = new Complex(ResistorTwo, 0);
            Complex Capaciti, Induction;
            ComentK= "коэфициенты передачи даны при отсутвие нагрузки";

            A = NezAparametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), FlagPoradokTwo);
            C = NezCParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), FlagPoradokTwo);

            if (!FlagPower || FlagChangedConstMode&&( LoadResit==0|| LoadInduc==0|| loadCapac==0))
            {

                B = NezBParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), 0, FlagPoradokTwo);
                D = DParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), 0, FlagPoradokTwo);    
            }
         
              if (FlagPower)
              {

                if (LoadResit != 0 && FlagPowerRessit)
                {
                    B = NezBParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), Complex.FromPolarCoordinates(LoadResit, 0), FlagPoradokTwo);
                    D = DParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), Complex.FromPolarCoordinates(LoadResit, 0), FlagPoradokTwo);

               /*     VoltageKDelitel = "Kд=" + Complex.Pow(NezAparametr(Complex.FromPolarCoordinates(ResistorOne, 0),
                                     Complex.FromPolarCoordinates(ResistorTwo, 0) * Complex.FromPolarCoordinates(LoadResit, 0)
                                     / (Complex.FromPolarCoordinates(ResistorTwo, 0) + Complex.FromPolarCoordinates(LoadResit, 0)), FlagPoradokTwo), -1).Magnitude;

                    VoltageK = "Ku=" + NezAparametr(Complex.FromPolarCoordinates(ResistorOne, 0),
                        Complex.FromPolarCoordinates(ResistorTwo, 0) * Complex.FromPolarCoordinates(LoadResit, 0)
                        / (Complex.FromPolarCoordinates(ResistorTwo, 0) + Complex.FromPolarCoordinates(LoadResit, 0)), FlagPoradokTwo).Magnitude;

                    AmperK = "Ki=" + NezCParametr(Complex.FromPolarCoordinates(ResistorOne, 0),
                        Complex.FromPolarCoordinates(ResistorTwo, 0) * Complex.FromPolarCoordinates(LoadResit, 0)
                        / (Complex.FromPolarCoordinates(ResistorTwo, 0) + Complex.FromPolarCoordinates(LoadResit, 0)), FlagPoradokTwo).Magnitude;*/
                }
                else
                {                                

                    if (flagChangedConstMode)
                    {
                        if (FlagPowerCapacity || FlagPowerInduction || LoadResit == 0) MessageBox.Show("не влияет или не заданы параметры ");
                        B = NezBParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), 0, FlagPoradokTwo);
                        D = DParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), 0, FlagPoradokTwo);                      
                    }

                    else
                    { 
                   
                        if( FlagPowerCapacity == true && LoadCapac == 0 || FlagPowerInduction == true && LoadInduc == 0|| (LoadResit == 0 && FlagPowerRessit==true))
                    {
                        MessageBox.Show("не влияет или не заданы параметры");
                            B = NezBParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), 0, FlagPoradokTwo);
                            D = DParametr(Complex.FromPolarCoordinates(ResistorOne, 0), Complex.FromPolarCoordinates(ResistorTwo, 0), 0, FlagPoradokTwo);
                           
                        }
                    
                        else
                    {
                            if (FlagPowerCapacity)
                        {
                            Capaciti = new Complex(0, -ResistCapacity(LoadCapac, Chactota));

                            D = DParametr(Resist1, Resist2, Capaciti, FlagPoradokTwo);
                            B = NezBParametr(Resist1, Resist2, Capaciti, FlagPoradokTwo);
           /*                     VoltageKDelitel = "Kд=" + Complex.Pow(NezAparametr(Complex.FromPolarCoordinates(ResistorOne, 0),
                                    Complex.FromPolarCoordinates(ResistorTwo, 0) * Complex.FromPolarCoordinates(LoadResit, 0)
                                    / (Complex.FromPolarCoordinates(ResistorTwo, 0) + Complex.FromPolarCoordinates(LoadResit, 0)), FlagPoradokTwo), -1).Magnitude;

                                VoltageK = "Ku=" + NezAparametr(Complex.FromPolarCoordinates(ResistorOne, 0),
                                    Complex.FromPolarCoordinates(ResistorTwo, 0)* Complex.FromPolarCoordinates(LoadResit, 0)
                                    / (Complex.FromPolarCoordinates(ResistorTwo, 0) + Complex.FromPolarCoordinates(LoadResit, 0)), FlagPoradokTwo ).Magnitude;

                                AmperK = "Ki=" + NezCParametr(Complex.FromPolarCoordinates(ResistorOne, 0),
                                    Complex.FromPolarCoordinates(ResistorTwo, 0) * Complex.FromPolarCoordinates(LoadResit, 0)
                                    / (Complex.FromPolarCoordinates(ResistorTwo, 0) + Complex.FromPolarCoordinates(LoadResit, 0)), FlagPoradokTwo).Magnitude;*/
                            }

                        if (FlagPowerInduction)
                        {

                            Induction = new Complex(0, ResistInduction(LoadInduc, Chactota));
                            D = DParametr(Resist1, Resist2, Induction, FlagPoradokTwo);
                            B = NezBParametr(Resist1, Resist2, Induction, FlagPoradokTwo);

                             /*   VoltageKDelitel = "Kд=" + Complex.Pow(K(A, B, Induction), -1).Magnitude;
                                VoltageK = "Ku=" + K(A, B, Induction).Magnitude;
                                AmperK = "Ki=" + Ki(C, D, Induction).Magnitude;*/

                            }

                    }
                     }
                }
               
            }

            DET = (A * D )- (B * C);

            /* AmperK = 
             * "Ki=" + Math.Round(Complex.Pow(D, -1).Magnitude, 2);*/

            ResitIn = "Z1c=(" + Math.Round(Complex.Sqrt((A * B) / (C * D)).Magnitude,2)+";"+ Math.Round(Complex.Sqrt((A * B) / (C * D)).Phase*180/Math.PI, 2) + ")";
            ResitOut= "Z2c=(" + Math.Round(Complex.Sqrt((D * B) / (C * A)).Magnitude, 2) + ";" + Math.Round(Complex.Sqrt((D * B) / (C * A)).Phase * 180 / Math.PI, 2) + ")";
            VoltageK = "Ku= " + Math.Round(Complex.Pow(A, -1).Magnitude, 2);
            VoltageKDelitel = "Kд=" + Math.Round(A.Magnitude, 2);
            AmperK = "Ki=" + 1;

            /**/
            if (ZParametr)
            {
                OneOne = "Z11=" + (A /C).Magnitude;
                TwoOne = "Z21=" + 1 / C;
                OneTwo="Z12="+ DET / C;
                TwoTwo="Z22="+ D /C;
            }
      /**/      if (YParametr)
            {
                OneOne = "Y11=" + D /B ;
                OneTwo = "Y12=" +-DET/ B;
                TwoOne = "Y21=" + -1 / B;
                TwoTwo = "Y22=" + A / B;
            }
           /**/ if (AParametr)
            {
                    OneOne = "A11=" + A.Magnitude;
                    TwoOne = "A21=" + C.Magnitude;
                        OneTwo = "A12=" + B.Magnitude;
                        TwoTwo = "A22=" + D.Magnitude;
              }          
      /**/      if (BParametr)
            {
       
                    OneOne = "B11=" + D;
                    OneTwo = "B12=" + B;
                TwoTwo = "B22=" + A;
                TwoOne = "B21=" + C;

            }
         /**/   if (HParametr)
            {
                OneOne = "H11=" + B / D;
                 OneTwo = "H12=" +DET / D;
                TwoOne = "H21=" + -1 / D;
                TwoTwo = "H22=" + C / D;
                

            }
        /**/    if (GParametr)
            {
                OneOne = "G11=" + C /A;
                OneTwo = "G12=" + -DET/ A;
                     TwoOne = "G21=" +DET / A;
                TwoTwo = "G22=" + B / A;

            }


        }
        /*------------------------------------------------------------------------------------------------*/

        public ICommand ComTwoVariantExecution { get; protected set; }
        private bool canComTwoVariantExecutionExecute(object p) => true;
      
        private void OnComTwoVariantExecutionExecuted(object p)
        {
            FlagOneScript = false;
        }
        /*------------------------------------------------------------------------------------------------*/

        public ICommand ComThereVariantExecution { get; protected set; }
        private bool canComThereVariantExecutionExecute(object p) => true;
      
        private void OnComThereVariantExecutionExecuted(object p)
        {
            FlagOneScript = false;
        }
        /*------------------------------------------------------------------------------------------------*/


        public ICommand ComForVariantExecution { get; protected set; }
        private bool canComForVariantExecutionExecute(object p) => true;
      
        private void OnComForVariantExecutionExecuted(object p)
        {
            FlagOneScript = false;
        }
        /*------------------------------------------------------------------------------------------------*/
        public ICommand CommandDiagramsOne { get; protected set; }
        public ICommand CommandDiagramsTwo { get; protected set; }
        public ICommand CommandDiagramsThere { get; protected set; }
        public ICommand CommandDiagramsFor { get; protected set; }

        public ICommand CommandGraphcsPerexod { get; protected set; }
        public ICommand CommandGraphcsImpuls { get; protected set; }
        public ICommand CommandCharestic { get; protected set; }
        #endregion

    }

}
